﻿using System;
using System.Collections.Generic;
using System.Web.Services;
using Meqs.Entity;
using Meqs.Logic.Interface;
using System.Collections;
using System.Collections.Generic;

public partial class SchLogin : BasePage
{
    protected const string SchoolMark = "School";
    protected int loginway = 1;
    protected string schoolName = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        //if (!GlobalApplication.Reged)
        //{
        //    //转向提示用户注册页面
        //    Response.Redirect("regErrorPage.htm");
        //    return;
        //}

        if (!IsPostBack)
        {
            Hashtable ht = new Hashtable();
            ht.Add("SchoolMark", SchoolMark);
            //查询学校信息表，获取该校学期值
            IList<SchoolInfo> listSchoolInfo = Container<ISchoolInfoLogic>.Instance.FindAll(ht);
            schoolName = listSchoolInfo.Count == 0 ? "" : listSchoolInfo[0].SchoolName;

            if (Request.Cookies["LoginWay"] != null)
            {
                loginway = int.Parse(Request.Cookies["LoginWay"].Value);
            }
        }
    }
    /// <summary>
    /// 判断是否可以使用
    /// </summary>
    /// <returns></returns>
    private bool CheckReg()
    {
        if (!GlobalApplication.Reged)
        {
            //获取注册对象
            IRegistrationLogic rlogic = Container<IRegistrationLogic>.Instance;
            IList<Registration> l = rlogic.FindAll();
            if (l != null && l.Count > 0)
            {
                try
                {
                    //比对加密字符结果
                    UserSerial u = new UserSerial(l[0].Data);
                    if (LoginCommon.Encrypt(u.SNum, LoginCommon.GetMacAddress()) == Convert.ToString(u.UserSecret))
                    {
                        //已经注册成功
                        GlobalApplication.Reged = true;
                        return true;
                    }
                    else
                    {
                        //没有注册
                        if (u.UsedNumber > 0)
                        {
                            //使用次数没到.可以使用
                            return true;
                        }
                    }
                }
                catch { }
            }
            return false;
        }
        return true;
    }

    /// <summary>
    /// 教师登陆
    /// </summary>
    /// <param name="schoolMark"></param>
    /// <param name="code"></param>
    /// <param name="pwd"></param>
    /// <returns></returns>
    [WebMethod]
    public static int TeaLogin(string schoolMark, string code, string pwd)
    {

        ITeacherInfoLogic studentInfoLogic = Container<ITeacherInfoLogic>.Instance;
        return studentInfoLogic.CheckLogin(schoolMark, code, pwd);
    }

    /// <summary>
    /// 学生登陆
    /// </summary>
    /// <param name="schoolMark"></param>
    /// <param name="code"></param>
    /// <param name="pwd"></param>
    /// <returns></returns>
    [WebMethod]
    public static int StuLogin(string schoolMark, string code, string pwd)
    {
        IStudentInfoLogic studentInfoLogic = Container<IStudentInfoLogic>.Instance;
        return studentInfoLogic.CheckLogin(schoolMark, code, pwd);

        //CheckLogin(string schoolMark, string stuCode, string pass)
        //return 1;

    }
}
